﻿using System;
using System.Collections.Generic;
using System.Text;


namespace LanguageInfo.Common.Utilities
{
	/// <summary>
	/// 描述：显示简单的信息框
	/// 作者：路晓阳
	/// 时间：2010-6-1
	/// </summary>
	public class MessageBox
	{
		/// <summary>
		/// 生成信息框的HTML
		/// </summary>
		/// <param name="title">信息框标题</param>
		/// <param name="message">信息内容</param>
		/// <param name="buttons">要显示的按钮</param>
		/// <returns></returns>
		static public string ShowString(string title, string message, params object[] buttons)
		{
			string css = "msg";
			if (title.IndexOf("错") > -1) css = "msg_alert";
            //if (string.IsNullOrEmpty(title))
            //    title = string.Format(" - {0} -", lang.MessageBox_Title);
			string msgHtml = @"<div id='msgbox'>
					<div class='msgtitle'>{0}</div>					
					<div class='{3}'>{1}</div>
					<div class='bts'>{2}</div>					
				</div>";
			msgHtml = string.Format(msgHtml, title, message, RenderButtons(buttons), css);

			return msgHtml;
		}

		/// <summary>
		/// 生成简单信息框的Literal控件
		/// </summary>
		/// <param name="title"></param>
		/// <param name="message"></param>
		/// <param name="buttons"></param>
		/// <returns></returns>
		static public System.Web.UI.LiteralControl Show(string title, string message, params object[] buttons)
		{
			System.Web.UI.LiteralControl msg = new System.Web.UI.LiteralControl(ShowString(title, message, buttons));
			return msg;
		}

		/// <summary>
		/// 自定义的默认按钮
		/// </summary>
		/// <param name="buttons"></param>
		/// <returns></returns>
		static string RenderButtons(object[] buttons)
		{
			string btStr = string.Empty;
			if (null == buttons) return btStr;
			for (int i = 0; i < buttons.Length; i++)
			{
				switch (buttons[i].ToString())
				{
                    //case "Close":
                    //    btStr += "<input type=button onclick=\"javascript:window.opener=null;window.close();\" value=\" " + lang.MessageBox_Close + " \" class=\"bt\">　";
                    //    break;
                    //case "Back":
                    //    btStr += "<input type=button onclick=\"javascript:history.go(-1);\" value=\" " + lang.MessageBox_Back + " \" class=\"bt\">　";
                    //    break;
                    //case "Home":
                    //    btStr += "<input type=button onclick=\"javascript:location.href='/'\" value=\" " + lang.MessageBox_Home + " \" class=\"bt\">　";
                    //    break;
                    //case "Login":
                    //    btStr += "<input type=button onclick=\"javascript:location.href='/login.aspx'\" value=\" " + lang.MessageBox_Login + " \" class=\"bt\">　";
                    //    break;
                    //case "Register":
                    //    btStr += "<input type=button onclick=\"javascript:location.href='register.aspx';\" value=\" " + lang.MessageBox_Register + " \" class=\"bt\">　";
                    //    break;
					default:
						btStr += buttons[i].ToString() + "　";
						break;
				}
			}
			return btStr;
		}
		/// <summary>
		/// 常用按钮
		/// </summary> 
		public enum CustomButtons
		{
			/// <summary>
			/// 关闭按钮
			/// </summary>
			Close,
			/// <summary>
			/// 返回按钮
			/// </summary>
			Back,
			/// <summary>
			/// 首页按钮
			/// </summary>
			Home,
			/// <summary>
			/// 注册按钮
			/// </summary>
			Register,
			/// <summary>
			/// 登陆按钮
			/// </summary>
			Login
		}
		/// <summary>
		/// 自定义按钮
		/// </summary>
		public class CustomButton
		{
			string _text, _action;

			/// <summary>
			/// 自定义按钮
			/// </summary>
			/// <param name="text"></param>
			/// <param name="action"></param>
			public CustomButton(string text, string action)
			{
				_text = text;
				_action = action;
			}

			/// <summary>
			/// 生成按钮HTML
			/// </summary>
			/// <returns></returns>
			public override string ToString()
			{
				return string.Format("<input type=button onclick=\"{0}\" value=\"{1}\" class=\"bt\">", _action, _text);
			}
		}

	}
}

